<form action="?section=check_out_2" method="POST" id="checkOutForm" myFor="rightContentBox">
<input type="hidden" value="<?php if ($user->address->id) print $user->address->id;?>" name="address_id">
<table class="formtable">
        <tr> 
		<th colspan="2">Dirección de Entrega:</th>
        </tr>
	<tr>
              <td colspan="2" class="hr"></td>
	</tr>
        <tr> 
		<td colspan="2">Las entregas son en Horario Comercial por lo que 
          muchas veces es preferible poner la dirección del trabajo si 
          no va a estar en su domicilio</td>
        </tr>
	<tr>
		<td class="hr" colspan="2"></td>
	</tr>
        <tr> 
		<td class="label"><label for="name">Nombre:</label></td>
		<td>
			<input type="text" value="<?php if ($user->id) print $user->address->firstname;?>" size="20" name="firstname" myExpected="rqd"> 
		</td>
        </tr>
        <tr> 
		<td class="label"><label for="lastname">Apellidos:</label></td>
		<td>
			<input type="TEXT" value="<?php if ($user->id) print $user->address->lastname;?>" size="30" name="lastname"> 
		</td>
        </tr>
        <tr>
		<td class="label"><label for="street_address">Dirección completa:</label></td>
		<td>
			<input type="text" value="<?php if ($user->id) print $user->address->street;?>" size="38" name="street" myExpected="rqd"> 
		</td>
        </tr>
        <tr>
		<td class="label"><label>País:</label></td>
		<td>
			<select id="country_id" name="country_id" myFor="changeZones" href="?section=zones&country=">
			<?php
				$sql="SELECT c.id, c.name FROM " .
					TABLE_COUNTRIES . " c" .
					" WHERE 1".
					" order by c.name asc";
				$result = $server->db->link->query($sql);
				$country_id=DEFAULT_COUNTRY_ID;
				if ( $user->id) {
					$country_id=$user->address->country_id;
				}
				for($i=0;$i<$result->num_rows;$i++) {
					list($Cid, $Cname)=$result->fetch_row();
					if ($Cid==$country_id) {
				?>
				<option value="<?php echo $Cid; ?>" selected="selected"><?php echo $Cname; ?></option>
				<?php
					}
					else {
				?>
				<option value="<?php echo $Cid; ?>"><?php echo $Cname; ?></option>
				<?php
					}
				}
				?>
			</select>
		</td>
        </tr>
        <tr> 
		<td class="label"><label for="city">Población:</label></td>
		<td><input type="text" value="<?php if ($user->id) print $user->address->city;?>" size="25" name="city"></td>
        </tr>
        <tr> 
		<td class="label"><label for="zone_id">Provincia:</label></td>
		<td>
			<select id="zone_id" name="zone_id">
				<?php
				$sql="SELECT z.id,z.name FROM " .
				TABLE_ZONES . " z" .
				" WHERE z.country_id=" . $country_id .
				" order by z.name asc";
				$result = $server->db->link->query($sql);
				for($i=0;$i<$result->num_rows;$i++) {
					list($Zid, $Zname)=$result->fetch_row();
					if ($user->id && $user->address->zone_id==$Zid) {
				?>
				<option value="<?php echo $Zid; ?>" selected="selected"><?php echo $Zname; ?></option>
				<?php
					}
					else {
				?>
				<option value="<?php echo $Zid; ?>"><?php echo $Zname; ?></option>
				<?php
					}
				}
				?>
			</select>
		</td>
        </tr>
        <tr>
		<td class="label"><label for="postcode">Código Postal:</label></td>
		<td>
			<input type="text" value="<?php if ($user->id) print $user->address->postcode;?>" size="25" name="postcode"> 
		</td>
        </tr>
        <tr>
		<td class="label"><label for="phone">Teléfono:</label></td>
		<td>
			<input type="text" value="<?php if ($user->id) print $user->phone; ?>" size="15" name="phone" myExpected="number rqd">
		</td>
        </tr>
        <tr>
		<td class="label"><label for="sec_phone">Otro teléfono:</label></td>
		<td>
			<input type="text" value="<?php if ($user->id) print $user->sec_phone; ?>" size="15" name="sec_phone">
		</td>
        </tr>
        <tr>
		<td class="label"><label for="comments">Comentarios:</label></td>
		<td>
			<textarea name="comments" rows="3" cols="40"></textarea> 
		</td>
        </tr>
	<tr>
              <td class="hr" colspan="2"></td>
	</tr>
</table>
<div class="space"></div>

<table class="formtable">
	<tr> 
		<th colspan="2">Forma de Envío:</th>
	</tr>
	<tr>
              <td class="hr" colspan="2"></td>
	</tr>
	<tr> 
		<td colspan="2">Elija la forma de envío que más le convenga.</td>
	</tr>
	<tr>
              <td class="hr" colspan="2"></td>
	</tr>
      
      <?php
	$delivery=new delivery();
	$delivery->db_load_shipping_types();
	for ($i=0; $i<count($delivery->shipping_types); $i++) {
	?>
	<tr> 
		<td>
			<input type="radio" name="shipping_type_id" value="<?php echo $delivery->shipping_types[$i]->id; ?>" SIZE="20" <?php if ($i==0) echo 'checked'; ?>>
		</td>
		<td>
			<?php echo $delivery->shipping_types[$i]->name; ?>
		</td>
      </tr>
	<?php
	}
	?>
	<tr>
              <td colspan="2" class="hr"></td>
	</tr>
</table>
<div class="space"></div>

<table class="formtable">
	<tr> 
		<th colspan="2">Forma de Pago:</th>
	</tr>
	<tr>
              <td class="hr" colspan="2"></td>
	</tr>
	<tr> 
		<td colspan="2">Elija la forma de pago que más le convenga.</td>
	</tr>
	<tr>
              <td class="hr" colspan="2"></td>
	</tr>
      
      <?php
	$payment=new payment();
	$payment->db_load_methods();
	for ($i=0; $i<count($payment->methods); $i++) {
	?>
	<tr> 
		<td>
			<input type="radio" name="payment_method_id" value="<?php echo $payment->methods[$i]->id; ?>" SIZE="20" <?php if ($i==0) echo 'checked'; ?>>
		</td>
		<td>
			<?php echo $payment->methods[$i]->name; ?>
		</td>
      </tr>
	<?php
	}
	?>
	<tr>
              <td colspan="2" class="hr"></td>
	</tr>
</table>
<div class="space"></div>
<input type="submit" id="formSubmitButton" value="Enviar Pedido">
</form>